Popular Searches
Popular Course Categories
Popular Courses

Explicit Wait

Waits in Selenium

<div class="selenium-notes">

<h1>Explicit Wait in Selenium</h1>

<p><strong>JustAcademy Selenium Training:</strong> <a href="https://www.justacademy.co/course-detail/selenium-training" target="_blank" rel="noopener noreferrer">JustAcademy Selenium Training Course</a></p>
<p><strong>JustAcademy Demo Registration:</strong> <a href="https://www.justacademy.co/register-for-course-demo" target="_blank" rel="noopener noreferrer">Register for Selenium Course Demo</a></p>

<p><strong>Explicit Wait</strong> in Selenium is a synchronization mechanism that allows WebDriver to wait for a specific condition to become true before continuing the test execution. Unlike Implicit Wait, which provides a general timeout for element searches, Explicit Wait is condition-specific and is especially useful for dynamic web applications where elements may appear, become visible, become enabled, become clickable, or change state after some time.</p>

<p>Explicit Wait is an important part of Selenium synchronization and dynamic-element handling. JustAcademy's Selenium curriculum includes Explicit Wait along with Implicit Wait, Fluent Wait, page load synchronization, dynamic element handling, and stable test execution strategies.</p>

<p>For structured Selenium learning covering WebDriver, WebElements, locators, waits, synchronization, dynamic elements, TestNG, Page Object Model, automation frameworks, and practical projects, visit <a href="https://www.justacademy.co/course-detail/selenium-training" target="_blank" rel="noopener noreferrer">Selenium Training Course</a>.</p>

<p>For a practical course demonstration, visit <a href="https://www.justacademy.co/register-for-course-demo" target="_blank" rel="noopener noreferrer">Selenium Course Demo</a>.</p>

<hr>

<h2>1. What is Explicit Wait?</h2>

<p>Explicit Wait is a Selenium synchronization technique used to wait for a particular condition before continuing execution. It allows the tester to define both the maximum waiting time and the condition that Selenium should monitor.</p>

<p>For example, a test may need to wait until a login button becomes clickable, a message becomes visible, a loader disappears, an alert appears, or a particular text is displayed.</p>

<pre><code>WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(10)

);</code></pre>

<hr>

<h2>2. Why is Explicit Wait Required?</h2>

<p>Modern web applications are often dynamic. Elements may not be immediately ready when Selenium reaches the corresponding test step.</p>

<ul>

<li>JavaScript may dynamically create elements.</li>

<li>AJAX or API requests may update the page asynchronously.</li>

<li>Buttons may become enabled after validation.</li>

<li>Loading indicators may remain visible while data is retrieved.</li>

<li>Messages may appear after form submission.</li>

<li>Menus may appear after user interaction.</li>

<li>Search results may load after an API response.</li>

<li>Animations may temporarily affect interaction.</li>

<li>SPA frameworks may update the DOM without a complete page reload.</li>

</ul>

<hr>

<h2>3. Basic Syntax of Explicit Wait</h2>

<pre><code>WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(10)

);</code></pre>

<p>Here, <strong>driver</strong> is the WebDriver instance and <strong>Duration.ofSeconds(10)</strong> specifies the maximum time that the explicit wait can wait for the condition.</p>

<hr>

<h2>4. Understanding WebDriverWait</h2>

<p><strong>WebDriverWait</strong> is a Selenium Java wait utility used to wait until a specified condition is satisfied or the timeout is reached.</p>

<table border="1" cellpadding="8" cellspacing="0">

<tr><th>Component</th><th>Meaning</th></tr>

<tr><td>WebDriverWait</td><td>Wait utility used for condition-based synchronization.</td></tr>

<tr><td>driver</td><td>The WebDriver instance controlling the browser.</td></tr>

<tr><td>Duration</td><td>Defines the maximum waiting period.</td></tr>

<tr><td>until()</td><td>Waits until the supplied condition is satisfied.</td></tr>

</table>

<hr>

<h2>5. Explicit Wait with until()</h2>

<p>The <strong>until()</strong> method is used to wait for a condition.</p>

<pre><code>WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(10)

);

 

WebElement element = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.id("message")

    )

);</code></pre>

<p>Selenium repeatedly evaluates the condition until it succeeds or the configured timeout is reached.</p>

<hr>

<h2>6. Explicit Wait Execution Flow</h2>

<pre><code>Test Starts

    ↓

Create WebDriver

    ↓

Create WebDriverWait

    ↓

Define Condition

    ↓

Selenium Checks Condition

    ↓

Condition Satisfied?

   ↙          ↘

 Yes           No

  ↓             ↓

Continue    Keep Polling

                ↓

        Timeout Reached?

           ↙       ↘

         No         Yes

          ↓          ↓

      Check Again  TimeoutException

</code></pre>

<hr>

<h2>7. Explicit Wait is Condition-Based</h2>

<p>The main advantage of Explicit Wait is that it waits for a meaningful condition rather than simply delaying execution for a fixed amount of time.</p>

<pre><code>WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(10)

);

 

wait.until(

    ExpectedConditions.elementToBeClickable(

        By.id("submit")

    )

);</code></pre>

<p>The test can continue as soon as the required condition is satisfied instead of always waiting for the entire ten seconds.</p>

<hr>

<h2>8. Explicit Wait vs Thread.sleep()</h2>

<table border="1" cellpadding="8" cellspacing="0">

<tr><th>Feature</th><th>Explicit Wait</th><th>Thread.sleep()</th></tr>

<tr><td>Type</td><td>Condition-based synchronization</td><td>Fixed delay</td></tr>

<tr><td>Condition</td><td>Yes</td><td>No</td></tr>

<tr><td>Efficiency</td><td>Can continue when condition is satisfied</td><td>Always waits the specified duration</td></tr>

<tr><td>Dynamic Applications</td><td>Suitable</td><td>Less suitable</td></tr>

<tr><td>Maintainability</td><td>Higher</td><td>Lower when used repeatedly</td></tr>

</table>

<hr>

<h2>9. Explicit Wait vs Implicit Wait</h2>

<table border="1" cellpadding="8" cellspacing="0">

<tr><th>Feature</th><th>Implicit Wait</th><th>Explicit Wait</th></tr>

<tr><td>Scope</td><td>General element searches</td><td>Specific condition</td></tr>

<tr><td>Condition-Specific</td><td>No</td><td>Yes</td></tr>

<tr><td>Visibility</td><td>No direct condition</td><td>Supported</td></tr>

<tr><td>Clickability</td><td>No direct condition</td><td>Supported</td></tr>

<tr><td>Text</td><td>No direct condition</td><td>Supported</td></tr>

<tr><td>Alert</td><td>No direct condition</td><td>Supported</td></tr>

<tr><td>Frame</td><td>No direct condition</td><td>Supported</td></tr>

<tr><td>Custom Condition</td><td>Not intended for this</td><td>Supported</td></tr>

</table>

<hr>

<h2>10. Explicit Wait and Dynamic Elements</h2>

<p>Dynamic elements may appear only after JavaScript execution, API responses, AJAX calls, or other asynchronous operations.</p>

<pre><code>Page Loaded

    ↓

JavaScript Executes

    ↓

API Request

    ↓

Response Received

    ↓

DOM Updated

    ↓

Element Becomes Visible

    ↓

Explicit Wait Detects Condition

    ↓

Test Continues</code></pre>

<hr>

<h2>11. Explicit Wait for Element Presence</h2>

<p><strong>presenceOfElementLocated()</strong> waits until an element is present in the DOM.</p>

<pre><code>WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(10)

);

 

WebElement username = wait.until(

    ExpectedConditions.presenceOfElementLocated(

        By.id("username")

    )

);</code></pre>

<p>Presence means the element has been located in the DOM. It does not necessarily mean that the element is visible or ready for interaction.</p>

<hr>

<h2>12. Explicit Wait for Element Visibility</h2>

<p><strong>visibilityOfElementLocated()</strong> waits until the element is present and visible.</p>

<pre><code>WebElement message = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.id("message")

    )

);</code></pre>

<p>This is useful when the test needs to interact with or validate a visible element.</p>

<hr>

<h2>13. Explicit Wait for Existing WebElement Visibility</h2>

<p>If a WebElement has already been located, <strong>visibilityOf()</strong> can be used.</p>

<pre><code>WebElement message =

    driver.findElement(By.id("message"));

 

WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(10)

);

 

wait.until(

    ExpectedConditions.visibilityOf(message)

);</code></pre>

<hr>

<h2>14. Explicit Wait for Clickability</h2>

<p><strong>elementToBeClickable()</strong> is commonly used when the test needs an element that is visible and enabled for interaction.</p>

<pre><code>WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(10)

);

 

WebElement button = wait.until(

    ExpectedConditions.elementToBeClickable(

        By.id("submit")

    )

);

 

button.click();</code></pre>

<hr>

<h2>15. Explicit Wait for Element to be Selected</h2>

<p><strong>elementToBeSelected()</strong> can be used when the test needs to wait until an element becomes selected.</p>

<pre><code>WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(10)

);

 

wait.until(

    ExpectedConditions.elementToBeSelected(

        By.id("terms")

    )

);</code></pre>

<hr>

<h2>16. Explicit Wait for Element to Become Selected or Unselected</h2>

<p><strong>elementSelectionStateToBe()</strong> can be used when the expected selected state needs to be explicitly defined.</p>

<pre><code>wait.until(

    ExpectedConditions.elementSelectionStateToBe(

        By.id("terms"),

        true

    )

);</code></pre>

<hr>

<h2>17. Explicit Wait for Text</h2>

<p><strong>textToBePresentInElementLocated()</strong> waits until expected text is present inside a located element.</p>

<pre><code>wait.until(

    ExpectedConditions.textToBePresentInElementLocated(

        By.id("status"),

        "Completed"

    )

);</code></pre>

<hr>

<h2>18. Explicit Wait for Text in an Existing WebElement</h2>

<p>When a WebElement is already available, Selenium provides conditions for checking expected text in that element.</p>

<pre><code>WebElement status =

    driver.findElement(By.id("status"));

 

wait.until(

    ExpectedConditions.textToBePresentInElement(

        status,

        "Completed"

    )

);</code></pre>

<hr>

<h2>19. Explicit Wait for Attribute Value</h2>

<p>Dynamic applications may update attributes such as class, value, aria attributes, or custom attributes.</p>

<pre><code>wait.until(

    ExpectedConditions.attributeToBe(

        By.id("status"),

        "class",

        "completed"

    )

);</code></pre>

<hr>

<h2>20. Explicit Wait for Attribute to Contain a Value</h2>

<p>When only part of an attribute value needs to be matched, an attribute-based condition can be useful.</p>

<pre><code>wait.until(

    ExpectedConditions.attributeContains(

        By.id("status"),

        "class",

        "active"

    )

);</code></pre>

<hr>

<h2>21. Explicit Wait for Invisibility</h2>

<p><strong>invisibilityOfElementLocated()</strong> is useful when a loader, spinner, overlay, or temporary element must disappear before the next operation.</p>

<pre><code>wait.until(

    ExpectedConditions.invisibilityOfElementLocated(

        By.id("loader")

    )

);</code></pre>

<hr>

<h2>22. Explicit Wait for Loading Spinner</h2>

<pre><code>WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(15)

);

 

wait.until(

    ExpectedConditions.invisibilityOfElementLocated(

        By.cssSelector(".loading-spinner")

    )

);</code></pre>

<p>This is often more meaningful than using a fixed sleep because the test can continue as soon as the loading indicator disappears.</p>

<hr>

<h2>23. Explicit Wait for Alert</h2>

<p>When an alert is expected to appear asynchronously, <strong>alertIsPresent()</strong> can be used.</p>

<pre><code>WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(10)

);

 

Alert alert = wait.until(

    ExpectedConditions.alertIsPresent()

);

 

alert.accept();</code></pre>

<hr>

<h2>24. Explicit Wait for Frame</h2>

<p>When an iframe may not immediately be available, an explicit wait can wait until the frame is available and switch to it.</p>

<pre><code>WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(10)

);

 

wait.until(

    ExpectedConditions.frameToBeAvailableAndSwitchToIt(

        By.id("paymentFrame")

    )

);</code></pre>

<hr>

<h2>25. Explicit Wait for Multiple Windows</h2>

<p>When a user action opens a new tab or window, a custom wait can be used to wait until the expected number of window handles exists.</p>

<pre><code>WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(10)

);

 

wait.until(

    d -&gt; d.getWindowHandles().size() &gt; 1

);</code></pre>

<hr>

<h2>26. Explicit Wait with Lambda Expression</h2>

<p>Explicit Wait can also use a lambda expression when the required condition is not directly represented by a built-in ExpectedConditions method.</p>

<pre><code>WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(10)

);

 

wait.until(

    d -&gt; d.findElement(By.id("status"))

          .getText()

          .equals("Completed")

);</code></pre>

<hr>

<h2>27. Explicit Wait for Custom Condition</h2>

<p>Custom conditions are useful when an application has a specific state that cannot be handled directly by a standard expected condition.</p>

<pre><code>wait.until(

    driver -&gt; {

        String status =

            driver.findElement(By.id("status"))

                  .getText();

        return status.equals("Success");

    }

);</code></pre>

<hr>

<h2>28. Explicit Wait for Button Enablement</h2>

<p>A button may initially be disabled and become enabled after the user completes required fields.</p>

<pre><code>WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(10)

);

 

WebElement submit = wait.until(

    driver -&gt; {

        WebElement button =

            driver.findElement(By.id("submit"));

        return button.isEnabled() ? button : null;

    }

);

 

submit.click();</code></pre>

<hr>

<h2>29. Explicit Wait for Login Button</h2>

<pre><code>driver.findElement(By.id("username"))

      .sendKeys("admin");

 

driver.findElement(By.id("password"))

      .sendKeys("password");

 

WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(10)

);

 

WebElement loginButton = wait.until(

    ExpectedConditions.elementToBeClickable(

        By.id("login")

    )

);

 

loginButton.click();</code></pre>

<hr>

<h2>30. Explicit Wait for Search Results</h2>

<pre><code>driver.findElement(By.id("search"))

      .sendKeys("Selenium");

 

driver.findElement(By.id("searchButton"))

      .click();

 

WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(10)

);

 

WebElement result = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.cssSelector(".search-result")

    )

);

 

System.out.println(result.getText());</code></pre>

<hr>

<h2>31. Explicit Wait for AJAX Content</h2>

<p>AJAX can update only part of a web page. The browser may remain on the same page while the required content is being loaded.</p>

<pre><code>User Action

    ↓

AJAX Request

    ↓

Server Processing

    ↓

Response

    ↓

DOM Update

    ↓

Explicit Wait

    ↓

Condition Satisfied

    ↓

Test Continues</code></pre>

<hr>

<h2>32. Explicit Wait for Dynamic Table Rows</h2>

<pre><code>WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(10)

);

 

List&lt;WebElement&gt; rows = wait.until(

    ExpectedConditions.visibilityOfAllElementsLocatedBy(

        By.cssSelector("table tbody tr")

    )

);

 

for(WebElement row : rows){

    System.out.println(row.getText());

}</code></pre>

<hr>

<h2>33. Explicit Wait for Product Cards</h2>

<pre><code>WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(10)

);

 

List&lt;WebElement&gt; products = wait.until(

    ExpectedConditions.visibilityOfAllElementsLocatedBy(

        By.cssSelector(".product-card")

    )

);

 

for(WebElement product : products){

    System.out.println(product.getText());

}</code></pre>

<hr>

<h2>34. Explicit Wait with XPath</h2>

<pre><code>WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(10)

);

 

WebElement login = wait.until(

    ExpectedConditions.elementToBeClickable(

        By.xpath("//button[@id='login']")

    )

);

 

login.click();</code></pre>

<hr>

<h2>35. Explicit Wait with CSS Selector</h2>

<pre><code>WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(10)

);

 

WebElement username = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.cssSelector("#username")

    )

);

 

username.sendKeys("admin");</code></pre>

<hr>

<h2>36. Explicit Wait with ID Locator</h2>

<pre><code>WebElement username = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.id("username")

    )

);

 

username.sendKeys("admin");</code></pre>

<hr>

<h2>37. Explicit Wait with Name Locator</h2>

<pre><code>WebElement username = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.name("username")

    )

);

 

username.sendKeys("admin");</code></pre>

<hr>

<h2>38. Explicit Wait with Class Name</h2>

<pre><code>WebElement button = wait.until(

    ExpectedConditions.elementToBeClickable(

        By.className("login-button")

    )

);

 

button.click();</code></pre>

<hr>

<h2>39. Explicit Wait and Presence vs Visibility</h2>

<table border="1" cellpadding="8" cellspacing="0">

<tr><th>Condition</th><th>Meaning</th></tr>

<tr><td>presenceOfElementLocated()</td><td>Element exists in the DOM.</td></tr>

<tr><td>visibilityOfElementLocated()</td><td>Element is present and visible.</td></tr>

<tr><td>elementToBeClickable()</td><td>Element is visible and enabled for interaction.</td></tr>

</table>

<hr>

<h2>40. Explicit Wait and Presence</h2>

<p>Presence is appropriate when the test only needs the element to exist in the DOM.</p>

<pre><code>WebElement element = wait.until(

    ExpectedConditions.presenceOfElementLocated(

        By.id("data")

    )

);</code></pre>

<p>Presence does not guarantee that the element is visible.</p>

<hr>

<h2>41. Explicit Wait and Visibility</h2>

<p>Visibility is appropriate when the element needs to be displayed before the test continues.</p>

<pre><code>WebElement element = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.id("data")

    )

);</code></pre>

<hr>

<h2>42. Explicit Wait and Clickability</h2>

<p>Clickability is useful when a test needs an element that is visible and enabled before attempting a click.</p>

<pre><code>WebElement element = wait.until(

    ExpectedConditions.elementToBeClickable(

        By.id("submit")

    )

);

 

element.click();</code></pre>

<hr>

<h2>43. Explicit Wait and isDisplayed()</h2>

<p>Explicit Wait can be combined with visibility conditions when the test requires a dynamically displayed element.</p>

<pre><code>WebElement message = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.id("message")

    )

);

 

System.out.println(

    message.isDisplayed()

);</code></pre>

<hr>

<h2>44. Explicit Wait and isEnabled()</h2>

<p>When a control becomes enabled dynamically, a custom condition or clickability condition can be used.</p>

<pre><code>WebElement button = wait.until(

    ExpectedConditions.elementToBeClickable(

        By.id("submit")

    )

);

 

System.out.println(

    button.isEnabled()

);</code></pre>

<hr>

<h2>45. Explicit Wait and isSelected()</h2>

<p>When a checkbox or radio button becomes selected after a user action or application update, an explicit selection condition can be used.</p>

<pre><code>wait.until(

    ExpectedConditions.elementToBeSelected(

        By.id("terms")

    )

);</code></pre>

<hr>

<h2>46. Explicit Wait for Checkbox</h2>

<pre><code>WebElement checkbox = wait.until(

    ExpectedConditions.elementToBeClickable(

        By.id("terms")

    )

);

 

if(!checkbox.isSelected()){

    checkbox.click();

}

 

wait.until(

    ExpectedConditions.elementToBeSelected(

        By.id("terms")

    )

);</code></pre>

<hr>

<h2>47. Explicit Wait for Radio Button</h2>

<pre><code>WebElement male = wait.until(

    ExpectedConditions.elementToBeClickable(

        By.id("male")

    )

);

 

male.click();

 

wait.until(

    ExpectedConditions.elementToBeSelected(

        By.id("male")

    )

);</code></pre>

<hr>

<h2>48. Explicit Wait for Toast Message</h2>

<pre><code>WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(10)

);

 

WebElement toast = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.cssSelector(".toast")

    )

);

 

System.out.println(toast.getText());</code></pre>

<hr>

<h2>49. Explicit Wait for Error Message</h2>

<pre><code>driver.findElement(By.id("login"))

      .click();

 

WebElement error = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.id("errorMessage")

    )

);

 

System.out.println(error.getText());</code></pre>

<hr>

<h2>50. Explicit Wait for Success Message</h2>

<pre><code>WebElement success = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.cssSelector(".success-message")

    )

);

 

String message = success.getText();

 

System.out.println(message);</code></pre>

<hr>

<h2>51. Explicit Wait for Modal</h2>

<pre><code>WebElement modal = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.id("confirmationModal")

    )

);

 

System.out.println(

    modal.getText()

);</code></pre>

<hr>

<h2>52. Explicit Wait for Modal to Disappear</h2>

<pre><code>wait.until(

    ExpectedConditions.invisibilityOfElementLocated(

        By.id("confirmationModal")

    )

);</code></pre>

<hr>

<h2>53. Explicit Wait for Dropdown</h2>

<pre><code>WebElement dropdown = wait.until(

    ExpectedConditions.elementToBeClickable(

        By.id("country")

    )

);

 

dropdown.click();</code></pre>

<hr>

<h2>54. Explicit Wait for Autocomplete Suggestions</h2>

<pre><code>driver.findElement(By.id("search"))

      .sendKeys("Selenium");

 

List&lt;WebElement&gt; suggestions = wait.until(

    ExpectedConditions.visibilityOfAllElementsLocatedBy(

        By.cssSelector(".suggestion")

    )

);

 

for(WebElement suggestion : suggestions){

    System.out.println(suggestion.getText());

}</code></pre>

<hr>

<h2>55. Explicit Wait for E-Commerce Product</h2>

<pre><code>driver.findElement(By.id("search"))

      .sendKeys("Laptop");

 

driver.findElement(By.id("searchButton"))

      .click();

 

WebElement product = wait.until(

    ExpectedConditions.elementToBeClickable(

        By.cssSelector(".product-card")

    )

);

 

product.click();</code></pre>

<hr>

<h2>56. Explicit Wait for Add to Cart Button</h2>

<pre><code>WebElement addToCart = wait.until(

    ExpectedConditions.elementToBeClickable(

        By.id("addToCart")

    )

);

 

addToCart.click();</code></pre>

<hr>

<h2>57. Explicit Wait for Checkout Button</h2>

<pre><code>WebElement checkout = wait.until(

    ExpectedConditions.elementToBeClickable(

        By.id("checkout")

    )

);

 

checkout.click();</code></pre>

<hr>

<h2>58. Explicit Wait for Dynamic Login Form</h2>

<pre><code>WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(10)

);

 

WebElement username = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.id("username")

    )

);

 

WebElement password = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.id("password")

    )

);

 

username.sendKeys("admin");

password.sendKeys("password");

 

WebElement login = wait.until(

    ExpectedConditions.elementToBeClickable(

        By.id("login")

    )

);

 

login.click();</code></pre>

<hr>

<h2>59. Explicit Wait with Page Navigation</h2>

<pre><code>driver.get("https://example.com/login");

 

WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(10)

);

 

WebElement username = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.id("username")

    )

);

 

username.sendKeys("admin");</code></pre>

<hr>

<h2>60. Explicit Wait for New Page Content</h2>

<pre><code>driver.findElement(By.id("login"))

      .click();

 

WebElement dashboard = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.id("dashboard")

    )

);

 

System.out.println(

    dashboard.getText()

);</code></pre>

<hr>

<h2>61. Explicit Wait and StaleElementReferenceException</h2>

<p>Dynamic applications may replace elements in the DOM. A previously stored WebElement can become stale after a DOM refresh or re-render.</p>

<pre><code>WebElement element =

    driver.findElement(By.id("dynamic"));

 

driver.navigate().refresh();

 

element.click();</code></pre>

<p>When the DOM changes, locating the element again inside the wait condition can be safer than relying on an old reference.</p>

<hr>

<h2>62. Re-Locating an Element During an Explicit Wait</h2>

<pre><code>WebElement element = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.id("dynamic")

    )

);

 

element.click();</code></pre>

<p>Using a locator-based condition allows Selenium to perform the lookup as part of the wait operation.</p>

<hr>

<h2>63. Explicit Wait and TimeoutException</h2>

<p>If the required condition does not become true within the configured timeout, Selenium can throw <strong>TimeoutException</strong>.</p>

<pre><code>WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(10)

);

 

wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.id("element")

    )

);</code></pre>

<hr>

<h2>64. Handling TimeoutException</h2>

<pre><code>try{

    WebElement element = wait.until(

        ExpectedConditions.visibilityOfElementLocated(

            By.id("element")

        )

    );

    System.out.println(element.getText());

}

catch(TimeoutException e){

    System.out.println(

        "Element did not become visible in time."

    );

}</code></pre>

<hr>

<h2>65. Explicit Wait and NoSuchElementException</h2>

<p>When a locator-based expected condition is used, the wait repeatedly performs the required lookup. If the condition cannot be satisfied before timeout, the wait ultimately fails.</p>

<pre><code>WebElement element = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.id("dynamicElement")

    )

);</code></pre>

<hr>

<h2>66. Explicit Wait and AJAX Search</h2>

<pre><code>driver.findElement(By.id("search"))

      .sendKeys("Selenium");

 

driver.findElement(By.id("searchButton"))

      .click();

 

wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.cssSelector(".search-results")

    )

);</code></pre>

<hr>

<h2>67. Explicit Wait for Loader and Content</h2>

<pre><code>wait.until(

    ExpectedConditions.invisibilityOfElementLocated(

        By.id("loader")

    )

);

 

WebElement content = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.id("content")

    )

);

 

System.out.println(content.getText());</code></pre>

<hr>

<h2>68. Explicit Wait with FluentWait</h2>

<p><strong>WebDriverWait</strong> is built on Selenium's fluent waiting mechanism. For advanced synchronization, a FluentWait can provide control over timeout, polling interval, and ignored exceptions.</p>

<pre><code>Wait&lt;WebDriver&gt; wait =

    new FluentWait&lt;WebDriver&gt;(driver)

        .withTimeout(Duration.ofSeconds(20))

        .pollingEvery(Duration.ofSeconds(2))

        .ignoring(NoSuchElementException.class);

 

WebElement element = wait.until(

    d -&gt; d.findElement(By.id("dynamic"))

);</code></pre>

<hr>

<h2>69. Explicit Wait Polling</h2>

<p>Explicit Wait does not normally execute one single check and immediately fail. It repeatedly evaluates the condition until it succeeds or the timeout is reached.</p>

<pre><code>Start

 ↓

Check Condition

 ↓

Condition True?

 ↙        ↘

Yes        No

 ↓          ↓

Continue   Poll Again

             ↓

        Timeout Reached?

</code></pre>

<hr>

<h2>70. Explicit Wait and Polling Interval</h2>

<p>For more advanced waiting requirements, polling frequency can be customized through FluentWait.</p>

<pre><code>Wait&lt;WebDriver&gt; wait =

    new FluentWait&lt;WebDriver&gt;(driver)

        .withTimeout(Duration.ofSeconds(20))

        .pollingEvery(Duration.ofSeconds(2));</code></pre>

<hr>

<h2>71. Explicit Wait with Ignored Exceptions</h2>

<p>FluentWait can be configured to ignore selected exceptions while polling for a condition.</p>

<pre><code>Wait&lt;WebDriver&gt; wait =

    new FluentWait&lt;WebDriver&gt;(driver)

        .withTimeout(Duration.ofSeconds(20))

        .pollingEvery(Duration.ofSeconds(2))

        .ignoring(NoSuchElementException.class);</code></pre>

<hr>

<h2>72. Explicit Wait and Page Object Model</h2>

<p>In a Page Object Model framework, explicit waits can be encapsulated inside page classes or reusable wait utilities.</p>

<pre><code>public class LoginPage {

 

    private WebDriver driver;

    private WebDriverWait wait;

 

    private By username =

        By.id("username");

 

    private By password =

        By.id("password");

 

    private By loginButton =

        By.id("login");

 

    public LoginPage(WebDriver driver){

        this.driver = driver;

        this.wait = new WebDriverWait(

            driver,

            Duration.ofSeconds(10)

        );

    }

 

    public void login(

        String user,

        String pass

    ){

        wait.until(

            ExpectedConditions.visibilityOfElementLocated(

                username

            )

        ).sendKeys(user);

 

        wait.until(

            ExpectedConditions.visibilityOfElementLocated(

                password

            )

        ).sendKeys(pass);

 

        wait.until(

            ExpectedConditions.elementToBeClickable(

                loginButton

            )

        ).click();

    }

}</code></pre>

<hr>

<h2>73. Explicit Wait Utility Class</h2>

<p>A reusable wait utility can reduce duplicate synchronization code in larger frameworks.</p>

<pre><code>public class WaitUtils {

 

    private WebDriver driver;

    private WebDriverWait wait;

 

    public WaitUtils(WebDriver driver){

        this.driver = driver;

        this.wait = new WebDriverWait(

            driver,

            Duration.ofSeconds(10)

        );

    }

 

    public WebElement waitForVisible(By locator){

        return wait.until(

            ExpectedConditions.visibilityOfElementLocated(

                locator

            )

        );

    }

 

    public WebElement waitForClickable(By locator){

        return wait.until(

            ExpectedConditions.elementToBeClickable(

                locator

            )

        );

    }

}</code></pre>

<hr>

<h2>74. Explicit Wait in TestNG</h2>

<pre><code>@BeforeMethod

public void setup(){

    driver = new ChromeDriver();

    driver.manage().window().maximize();

}

 

@Test

public void loginTest(){

 

    driver.get("https://example.com/login");

 

    WebDriverWait wait = new WebDriverWait(

        driver,

        Duration.ofSeconds(10)

    );

 

    wait.until(

        ExpectedConditions.visibilityOfElementLocated(

            By.id("username")

        )

    ).sendKeys("admin");

 

    wait.until(

        ExpectedConditions.visibilityOfElementLocated(

            By.id("password")

        )

    ).sendKeys("password");

 

    wait.until(

        ExpectedConditions.elementToBeClickable(

            By.id("login")

        )

    ).click();

}</code></pre>

<hr>

<h2>75. Explicit Wait with Assertions</h2>

<pre><code>WebElement dashboard = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.id("dashboard")

    )

);

 

Assert.assertTrue(

    dashboard.isDisplayed()

);</code></pre>

<hr>

<h2>76. Explicit Wait in Data-Driven Testing</h2>

<p>Explicit Wait can be reused while executing the same workflow with multiple test data sets.</p>

<pre><code>for(String username : usernames){

 

    WebElement input = wait.until(

        ExpectedConditions.visibilityOfElementLocated(

            By.id("username")

        )

    );

 

    input.clear();

    input.sendKeys(username);

}</code></pre>

<hr>

<h2>77. Explicit Wait in Cross-Browser Testing</h2>

<p>Explicit Wait works with Selenium WebDriver regardless of whether the test is executed against Chrome, Firefox, Edge, or another supported browser.</p>

<pre><code>WebDriver driver = new ChromeDriver();

 

WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(10)

);

 

WebElement element = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.id("username")

    )

);</code></pre>

<hr>

<h2>78. Explicit Wait in CI/CD</h2>

<p>CI/CD environments can have different execution characteristics from local systems. Condition-based waits can help tests synchronize with actual application state instead of relying on fixed delays.</p>

<pre><code>Local Machine

    ↓

Application Response

    ↓

Condition Check

    ↓

Test Continues

 

CI Server

    ↓

Application Response

    ↓

Condition Check

    ↓

Test Continues</code></pre>

<hr>

<h2>79. Choosing Explicit Wait Duration</h2>

<p>The timeout should be realistic for the application and execution environment.</p>

<table border="1" cellpadding="8" cellspacing="0">

<tr><th>Timeout</th><th>Possible Effect</th></tr>

<tr><td>Very Short</td><td>May cause failures when the application is temporarily slow.</td></tr>

<tr><td>Reasonable</td><td>Allows normal application response variation.</td></tr>

<tr><td>Very Long</td><td>Can delay failure detection and increase test execution time.</td></tr>

</table>

<hr>

<h2>80. Explicit Wait Does Not Fix Incorrect Locators</h2>

<p>Waiting cannot correct a locator that does not identify the required element.</p>

<pre><code>wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.id("incorrect-id")

    )

);</code></pre>

<p>If the actual element uses a different ID, increasing the timeout will not make the locator correct.</p>

<hr>

<h2>81. Explicit Wait Does Not Fix Application Bugs</h2>

<p>If an application has a genuine defect and the expected element or state never occurs, an explicit wait will eventually fail with a timeout. A wait should synchronize with expected application behavior, not hide application defects.</p>

<hr>

<h2>82. Explicit Wait Does Not Guarantee Successful Click</h2>

<p><strong>elementToBeClickable()</strong> checks whether an element is visible and enabled, but a click can still fail because of overlays, DOM changes, interception, browser behavior, animations, or other application conditions.</p>

<pre><code>WebElement button = wait.until(

    ExpectedConditions.elementToBeClickable(

        By.id("submit")

    )

);

 

button.click();</code></pre>

<hr>

<h2>83. Explicit Wait and Overlays</h2>

<p>A transparent or visible overlay can block interaction with an element. In such cases, waiting for the target element alone may not be enough.</p>

<pre><code>wait.until(

    ExpectedConditions.invisibilityOfElementLocated(

        By.id("overlay")

    )

);

 

wait.until(

    ExpectedConditions.elementToBeClickable(

        By.id("submit")

    )

).click();</code></pre>

<hr>

<h2>84. Explicit Wait for Animation Completion</h2>

<p>Animations can temporarily affect interaction. A framework may wait for a relevant state or for the animation-related element to disappear or reach the expected state.</p>

<pre><code>wait.until(

    ExpectedConditions.invisibilityOfElementLocated(

        By.cssSelector(".animation-loader")

    )

);</code></pre>

<hr>

<h2>85. Explicit Wait for Frame Switching</h2>

<pre><code>wait.until(

    ExpectedConditions.frameToBeAvailableAndSwitchToIt(

        By.cssSelector("iframe.payment")

    )

);

 

driver.findElement(By.id("cardNumber"))

      .sendKeys("123456789");</code></pre>

<hr>

<h2>86. Explicit Wait for Alert and Handling</h2>

<pre><code>driver.findElement(By.id("delete"))

      .click();

 

Alert alert = wait.until(

    ExpectedConditions.alertIsPresent()

);

 

System.out.println(alert.getText());

alert.accept();</code></pre>

<hr>

<h2>87. Explicit Wait for Window or Tab</h2>

<pre><code>String originalWindow =

    driver.getWindowHandle();

 

driver.findElement(By.id("open"))

      .click();

 

wait.until(

    d -&gt; d.getWindowHandles().size() &gt; 1

);

 

for(String window : driver.getWindowHandles()){

    if(!window.equals(originalWindow)){

        driver.switchTo().window(window);

        break;

    }

}</code></pre>

<hr>

<h2>88. Explicit Wait for Dynamic URL</h2>

<p>A custom condition can be used when navigation is expected to result in a particular URL.</p>

<pre><code>wait.until(

    ExpectedConditions.urlContains("dashboard")

);</code></pre>

<hr>

<h2>89. Explicit Wait for Title</h2>

<p>Selenium provides conditions for waiting until the page title contains or matches expected text.</p>

<pre><code>wait.until(

    ExpectedConditions.titleContains("Dashboard")

);</code></pre>

<hr>

<h2>90. Explicit Wait for URL</h2>

<pre><code>wait.until(

    ExpectedConditions.urlToBe(

        "https://example.com/dashboard"

    )

);</code></pre>

<hr>

<h2>91. Explicit Wait for DOM State</h2>

<p>When a specific DOM state represents application readiness, a custom lambda can be used.</p>

<pre><code>wait.until(

    driver -&gt; driver.findElement(

        By.id("status")

    ).getAttribute("data-state")

     .equals("ready")

);</code></pre>

<hr>

<h2>92. Explicit Wait for Application Status</h2>

<pre><code>wait.until(

    driver -&gt; {

        WebElement status =

            driver.findElement(By.id("status"));

        return status.getText().equals("Ready");

    }

);</code></pre>

<hr>

<h2>93. Explicit Wait for Dynamic Form Validation</h2>

<pre><code>driver.findElement(By.id("email"))

      .sendKeys("[email protected]");

 

wait.until(

    ExpectedConditions.attributeContains(

        By.id("email"),

        "class",

        "valid"

    )

);</code></pre>

<hr>

<h2>94. Explicit Wait for Search Suggestion</h2>

<pre><code>driver.findElement(By.id("search"))

      .sendKeys("Selenium");

 

List&lt;WebElement&gt; suggestions = wait.until(

    ExpectedConditions.visibilityOfAllElementsLocatedBy(

        By.cssSelector(".suggestion-item")

    )

);

 

suggestions.get(0).click();</code></pre>

<hr>

<h2>95. Explicit Wait for Notification</h2>

<pre><code>WebElement notification = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.cssSelector(".notification")

    )

);

 

Assert.assertTrue(

    notification.getText()

               .contains("Success")

);</code></pre>

<hr>

<h2>96. Explicit Wait for File Upload Result</h2>

<p>When a file upload causes a status element to appear, Selenium can wait for that status instead of relying on a fixed delay.</p>

<pre><code>driver.findElement(By.id("file"))

      .sendKeys("/path/to/file.pdf");

 

WebElement status = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.id("uploadStatus")

    )

);

 

System.out.println(status.getText());</code></pre>

<hr>

<h2>97. Explicit Wait for Download Completion</h2>

<p>For downloads, the synchronization requirement is often outside the DOM. The test may need to verify the filesystem or application download status rather than simply waiting for a web element.</p>

<pre><code>driver.findElement(By.id("download"))

      .click();

 

wait.until(

    driver -&gt; {

        return new File(

            "/downloads/report.pdf"

        ).exists();

    }

);</code></pre>

<hr>

<h2>98. Explicit Wait and Stable Locators</h2>

<p>A good synchronization strategy should be combined with stable locators. Explicit Wait cannot compensate for locators that frequently change or identify the wrong element.</p>

<ul>

<li>Prefer stable IDs when available.</li>

<li>Use meaningful CSS selectors.</li>

<li>Use reliable XPath expressions when necessary.</li>

<li>Avoid unnecessary absolute XPath.</li>

<li>Avoid locating elements using unstable dynamic values when better options exist.</li>

</ul>

<hr>

<h2>99. Explicit Wait Best Practices</h2>

<ul>

<li>Use Explicit Wait for specific application conditions.</li>

<li>Choose realistic timeout values.</li>

<li>Use condition-based synchronization instead of arbitrary delays.</li>

<li>Use stable locators.</li>

<li>Wait for the actual state required by the next test action.</li>

<li>Use visibility conditions when visibility is required.</li>

<li>Use clickability conditions when clicking is required.</li>

<li>Use invisibility conditions for loaders and overlays.</li>

<li>Use custom conditions for application-specific states.</li>

<li>Keep reusable waits in framework utilities where appropriate.</li>

<li>Avoid unnecessary Thread.sleep() calls.</li>

<li>Handle TimeoutException meaningfully.</li>

<li>Do not use excessive timeout values.</li>

<li>Keep synchronization logic maintainable.</li>

</ul>

<hr>

<h2>100. Common Mistakes with Explicit Wait</h2>

<ul>

<li>Using Thread.sleep() instead of condition-based waiting.</li>

<li>Waiting for presence when visibility is actually required.</li>

<li>Waiting for visibility when clickability is required.</li>

<li>Using incorrect locators.</li>

<li>Using extremely large timeout values.</li>

<li>Ignoring TimeoutException.</li>

<li>Waiting for the wrong application condition.</li>

<li>Using stale WebElement references.</li>

<li>Adding waits everywhere without understanding the actual synchronization requirement.</li>

<li>Using multiple wait mechanisms without a clear framework strategy.</li>

</ul>

<hr>

<h2>101. Explicit Wait and Synchronization Strategy</h2>

<pre><code>Application Action

    ↓

Application Processing

    ↓

Identify Required State

    ↓

Choose Correct Expected Condition

    ↓

Create Explicit Wait

    ↓

Wait Until Condition

    ↓

Condition Satisfied

    ↓

Perform Next Action

    ↓

Validate Result</code></pre>

<hr>

<h2>102. Explicit Wait Decision Table</h2>

<table border="1" cellpadding="8" cellspacing="0">

<tr><th>Requirement</th><th>Recommended Condition</th></tr>

<tr><td>Element exists in DOM</td><td>presenceOfElementLocated()</td></tr>

<tr><td>Element is visible</td><td>visibilityOfElementLocated()</td></tr>

<tr><td>Element can be clicked</td><td>elementToBeClickable()</td></tr>

<tr><td>Element is selected</td><td>elementToBeSelected()</td></tr>

<tr><td>Text appears</td><td>textToBePresentInElementLocated()</td></tr>

<tr><td>Loader disappears</td><td>invisibilityOfElementLocated()</td></tr>

<tr><td>Alert appears</td><td>alertIsPresent()</td></tr>

<tr><td>Frame becomes available</td><td>frameToBeAvailableAndSwitchToIt()</td></tr>

<tr><td>URL changes</td><td>urlContains() or urlToBe()</td></tr>

<tr><td>Title changes</td><td>titleContains() or titleIs()</td></tr>

<tr><td>Custom application state</td><td>Lambda or custom condition</td></tr>

</table>

<hr>

<h2>103. Practical Login Automation Example</h2>

<pre><code>import java.time.Duration;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.support.ui.ExpectedConditions;

import org.openqa.selenium.support.ui.WebDriverWait;

 

public class ExplicitWaitLoginTest {

 

    public static void main(String[] args) {

 

        WebDriver driver = new ChromeDriver();

 

        driver.manage().window().maximize();

 

        driver.get("https://example.com/login");

 

        WebDriverWait wait = new WebDriverWait(

            driver,

            Duration.ofSeconds(10)

        );

 

        WebElement username = wait.until(

            ExpectedConditions.visibilityOfElementLocated(

                By.id("username")

            )

        );

 

        username.sendKeys("admin");

 

        WebElement password = wait.until(

            ExpectedConditions.visibilityOfElementLocated(

                By.id("password")

            )

        );

 

        password.sendKeys("password");

 

        WebElement loginButton = wait.until(

            ExpectedConditions.elementToBeClickable(

                By.id("login")

            )

        );

 

        loginButton.click();

 

        WebElement dashboard = wait.until(

            ExpectedConditions.visibilityOfElementLocated(

                By.id("dashboard")

            )

        );

 

        System.out.println(

            "Dashboard: " + dashboard.getText()

        );

 

        driver.quit();

    }

}</code></pre>

<hr>

<h2>104. Practical E-Commerce Example</h2>

<pre><code>WebDriver driver = new ChromeDriver();

 

WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(15)

);

 

driver.get("https://example.com");

 

WebElement search = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.id("search")

    )

);

 

search.sendKeys("Laptop");

 

wait.until(

    ExpectedConditions.elementToBeClickable(

        By.id("searchButton")

    )

).click();

 

WebElement product = wait.until(

    ExpectedConditions.elementToBeClickable(

        By.cssSelector(".product-card")

    )

);

 

product.click();

 

wait.until(

    ExpectedConditions.elementToBeClickable(

        By.id("addToCart")

    )

).click();

 

wait.until(

    ExpectedConditions.elementToBeClickable(

        By.id("checkout")

    )

).click();

 

driver.quit();</code></pre>

<hr>

<h2>105. Practical Registration Example</h2>

<pre><code>WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(10)

);

 

wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.id("name")

    )

).sendKeys("John");

 

wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.id("email")

    )

).sendKeys("[email protected]");

 

wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.id("password")

    )

).sendKeys("Password123");

 

wait.until(

    ExpectedConditions.elementToBeClickable(

        By.id("register")

    )

).click();

 

WebElement success = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.id("success")

    )

);

 

System.out.println(success.getText());</code></pre>

<hr>

<h2>106. Practical Dynamic Dashboard Example</h2>

<pre><code>driver.get("https://example.com/dashboard");

 

WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(15)

);

 

wait.until(

    ExpectedConditions.invisibilityOfElementLocated(

        By.id("loader")

    )

);

 

WebElement dashboard = wait.until(

    ExpectedConditions.visibilityOfElementLocated(

        By.id("dashboard")

    )

);

 

WebElement reports = wait.until(

    ExpectedConditions.elementToBeClickable(

        By.id("reports")

    )

);

 

reports.click();</code></pre>

<hr>

<h2>107. Explicit Wait Interview Question: What is Explicit Wait?</h2>

<p><strong>Answer:</strong> Explicit Wait is a Selenium synchronization mechanism that waits for a specific condition to become true before allowing test execution to continue or until the configured timeout is reached.</p>

<hr>

<h2>108. Interview Question: How do you create an Explicit Wait?</h2>

<pre><code>WebDriverWait wait = new WebDriverWait(

    driver,

    Duration.ofSeconds(10)

);</code></pre>

<hr>

<h2>109. Interview Question: What is the purpose of until()?</h2>

<p><strong>Answer:</strong> The <strong>until()</strong> method waits until the supplied condition is satisfied or the configured timeout is reached.</p>

<hr>

<h2>110. Interview Question: What is ExpectedConditions?</h2>

<p><strong>Answer:</strong> ExpectedConditions is a Selenium utility that provides commonly used conditions for Explicit Wait, such as visibility, presence, clickability, text, alerts, frames, selection, URLs, titles, and other states.</p>

<hr>

<h2>111. Interview Question: What is the difference between presence and visibility?</h2>

<p><strong>Answer:</strong> Presence means the element exists in the DOM. Visibility means the element is present and displayed according to WebDriver's visibility rules.</p>

<hr>

<h2>112. Interview Question: What is elementToBeClickable()?</h2>

<p><strong>Answer:</strong> elementToBeClickable() is an ExpectedCondition used to wait until an element is visible and enabled for interaction.</p>

<hr>

<h2>113. Interview Question: What happens when Explicit Wait times out?</h2>

<p><strong>Answer:</strong> If the required condition does not become true within the configured timeout, Selenium generally throws a <strong>TimeoutException</strong>.</p>

<hr>

<h2>114. Interview Question: Can Explicit Wait handle dynamic elements?</h2>

<p><strong>Answer:</strong> Yes. Explicit Wait is particularly useful for dynamic elements because it can wait for specific states such as presence, visibility, clickability, text, selection, or custom application conditions.</p>

<hr>

<h2>115. Interview Question: Can Explicit Wait replace Thread.sleep()?</h2>

<p><strong>Answer:</strong> For normal synchronization requirements, condition-based Explicit Wait is generally more appropriate than fixed Thread.sleep() delays because it waits for the required state rather than an arbitrary amount of time.</p>

<hr>

<h2>116. Interview Question: Can Explicit Wait wait for an alert?</h2>

<p><strong>Answer:</strong> Yes. Selenium provides <strong>alertIsPresent()</strong> for waiting until a JavaScript alert is available.</p>

<pre><code>Alert alert = wait.until(

    ExpectedConditions.alertIsPresent()

);</code></pre>

<hr>

<h2>117. Interview Question: Can Explicit Wait wait for an iframe?</h2>

<p><strong>Answer:</strong> Yes. Selenium provides <strong>frameToBeAvailableAndSwitchToIt()</strong> for waiting until a frame is available and switching into it.</p>

<hr>

<h2>118. Interview Question: Can Explicit Wait wait for text?</h2>

<p><strong>Answer:</strong> Yes. Conditions such as <strong>textToBePresentInElementLocated()</strong> can be used when test execution depends on dynamic text.</p>

<hr>

<h2>119. Interview Question: Can Explicit Wait wait for a loader to disappear?</h2>

<p><strong>Answer:</strong> Yes. <strong>invisibilityOfElementLocated()</strong> can be used to wait until a loading indicator or other temporary element becomes invisible.</p>

<hr>

<h2>120. Interview Question: What is the difference between Explicit Wait and Fluent Wait?</h2>

<p><strong>Answer:</strong> WebDriverWait provides a convenient condition-based waiting mechanism, while FluentWait provides more configurable control over timeout, polling interval, and ignored exceptions. WebDriverWait is built on Selenium's fluent waiting mechanism.</p>

<hr>

<h2>121. Interview Question: Should Implicit and Explicit Wait be mixed?</h2>

<p><strong>Answer:</strong> They can be configured together, but their interaction should be understood because mixing them without a clear strategy can make timeout behavior harder to reason about. A consistent synchronization strategy is generally easier to maintain.</p>

<hr>

<h2>122. Interview Question: Does Explicit Wait fix incorrect locators?</h2>

<p><strong>Answer:</strong> No. Explicit Wait only waits for the condition associated with the locator. If the locator is incorrect, the expected condition will not become true.</p>

<hr>

<h2>123. Interview Question: Does Explicit Wait guarantee click success?</h2>

<p><strong>Answer:</strong> No. elementToBeClickable() waits for visibility and enabled state, but actual interaction can still be affected by overlays, DOM changes, interception, animations, or other browser/application conditions.</p>

<hr>

<h2>124. Explicit Wait Quick Reference</h2>

<table border="1" cellpadding="8" cellspacing="0">

<tr><th>Concept</th><th>Details</th></tr>

<tr><td>Primary Class</td><td>WebDriverWait</td></tr>

<tr><td>Main Method</td><td>until()</td></tr>

<tr><td>Purpose</td><td>Condition-specific synchronization.</td></tr>

<tr><td>Common Condition</td><td>visibilityOfElementLocated()</td></tr>

<tr><td>Clickable Condition</td><td>elementToBeClickable()</td></tr>

<tr><td>Presence Condition</td><td>presenceOfElementLocated()</td></tr>

<tr><td>Text Condition</td><td>textToBePresentInElementLocated()</td></tr>

<tr><td>Alert Condition</td><td>alertIsPresent()</td></tr>

<tr><td>Frame Condition</td><td>frameToBeAvailableAndSwitchToIt()</td></tr>

<tr><td>Selection Condition</td><td>elementToBeSelected()</td></tr>

<tr><td>Invisible Condition</td><td>invisibilityOfElementLocated()</td></tr>

<tr><td>Failure</td><td>TimeoutException when condition is not satisfied within timeout.</td></tr>

</table>

<hr>

<h2>125. Explicit Wait Revision Notes</h2>

<ul>

<li><strong>Explicit Wait:</strong> Condition-based Selenium synchronization.</li>

<li><strong>Class:</strong> WebDriverWait.</li>

<li><strong>Main Method:</strong> until().</li>

<li><strong>Purpose:</strong> Wait for a specific application state.</li>

<li><strong>Presence:</strong> Wait until an element exists in the DOM.</li>

<li><strong>Visibility:</strong> Wait until an element is visible.</li>

<li><strong>Clickability:</strong> Wait until an element is visible and enabled.</li>

<li><strong>Invisibility:</strong> Wait until an element disappears.</li>

<li><strong>Text:</strong> Wait until expected text appears.</li>

<li><strong>Alert:</strong> Wait until an alert is present.</li>

<li><strong>Frame:</strong> Wait until an iframe is available.</li>

<li><strong>Custom Condition:</strong> Use lambda or custom logic.</li>

<li><strong>Timeout:</strong> Use realistic values.</li>

<li><strong>Best Practice:</strong> Prefer condition-based synchronization over arbitrary fixed delays.</li>

</ul>

<hr>

<h2>126. Final Summary</h2>

<p><strong>Explicit Wait</strong> is one of the most useful synchronization mechanisms in Selenium automation. It allows a test to wait for a specific condition before continuing execution. This makes it particularly useful for modern dynamic web applications where elements can appear, disappear, become visible, become enabled, change text, or update their state asynchronously.</p>

<p>The basic Selenium Java syntax is <strong>WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));</strong>. The <strong>until()</strong> method is then used with a suitable expected condition.</p>

<p>Common conditions include <strong>presenceOfElementLocated()</strong>, <strong>visibilityOfElementLocated()</strong>, <strong>elementToBeClickable()</strong>, <strong>textToBePresentInElementLocated()</strong>, <strong>invisibilityOfElementLocated()</strong>, <strong>alertIsPresent()</strong>, <strong>frameToBeAvailableAndSwitchToIt()</strong>, and <strong>elementToBeSelected()</strong>.</p>

<p>Explicit Wait is different from Implicit Wait because it is condition-specific, while Implicit Wait provides a general timeout for applicable element searches. Explicit Wait is also different from Thread.sleep(), because it can stop waiting as soon as the required condition is satisfied rather than always pausing for a fixed duration.</p>

<p>A reliable Selenium framework should use meaningful conditions, stable locators, realistic timeout values, reusable wait utilities, and synchronization based on actual application state. Explicit Wait should be used to synchronize with expected application behavior rather than to hide incorrect locators or application defects.</p>

<p>For detailed Selenium automation training covering WebDriver, locators, waits, synchronization, dynamic elements, TestNG, Page Object Model, frameworks, and practical automation projects, visit <a href="https://www.justacademy.co/course-detail/selenium-training" target="_blank" rel="noopener noreferrer">Selenium Training Course</a>.</p>

<p>To explore a practical Selenium course demonstration, visit <a href="https://www.justacademy.co/register-for-course-demo" target="_blank" rel="noopener noreferrer">Register for Selenium Course Demo</a>.</p>

</div>

Previous Next
whatsapp